<template>
  <div>
    <div class="add-mj-con">
      <div class="top-info">
        <div class="left">新增满减券</div>
      </div>
      <form class="form" autocomplete="off" @submit.prevent="validateBeforeSubmit">
        <div class="bottom-info">

          <div class="left">
            <label for="">满：</label>
            <input type="text" v-validate="'required'" class="text-input" placeholder="请填写金额" v-model="reach1" name="reach1">

          </div>
          <div class="right">
            <label for="">减：</label>
            <input type="text" v-validate="'required'" class="text-input" placeholder="请填写金额" v-model="score1" name="score1">
          </div>
        </div>
        <div class="errortip">
          <span v-show="errors.has('reach1')">请填写金额</span>
        </div>
        <input type="submit" value="提交" class="sub-btn">
      </form>
    </div>

  </div>
</template>
<style scoped>
  @import "../../../assets/business/css/add_mj.css";
</style>
<script>
  export default {
    data() {
      return {
        reach1: "",
        score1: ""
      }
    },
    methods: {
      addcate: function () {
        console.log(this.errors);
        console.log(this.errors.items);
        this.$http.post(this.APIURL_PREFIX + '/api/wap/coupon/', $.param({ reach1: this.reach1 * 100, score1: this.score1 * 100 })).then((response) => {
          console.log(response.data);
          layer.msg("添加成功!");
          this.$router.push({ name: 'Business_discount_set' })
        }).catch(function (err) {
          console.log(err);
          layer.msg("添加失败");
         
        });
      },
      validateBeforeSubmit() {
        this.$validator.validateAll().then((result) => {
          if (result) {
            this.addcate()
          }
        }).catch(() => {
          layer.msg("表单验证错误")
          console.log('Correct them errors!');
        });
      }
    },
    mounted() {
    },
    components: {
    },
  }
</script>
